home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / util / logging / XMLFormatter.js < prev   
Encoding:
Text File  |  2007-04-11  |  3.5 KB  |  110 lines

  1. /****i* SOURCE_FILE/INFO
  2.   *
  3.   * NAME
  4.   *  XMLFormatter.js
  5.   *
  6.   * USAGE
  7.   *  Part of Netobjects JavaScript Library.
  8.   *
  9.   * COPYRIGHT
  10.   *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.   *  All Rights Reserved.
  12.   *
  13.   *  This is an unpublished work protected by Website Pros, Inc.
  14.   *  as a trade secret, and is not to be used or disclosed except as
  15.   *  expressly provided in a written license agreement executed by
  16.   *  you and Website Pros, Inc.
  17.   *
  18.   *      <copyright@websitepros.com>
  19.   *
  20.   * NOTES
  21.   *  JavaScript code.
  22.   *
  23.   *****/
  24.  
  25. if (!IS_isModuleInitialized("IS.NOF.UTIL.LOGGING.XMLFormatter"))
  26. {   
  27.   /****h* NOF_JavaScript_Library/NOF.UTIL.LOGGING.XMLFormatter
  28.     *
  29.     * NAME
  30.     *  NOF.UTIL.LOGGING.XMLFormatter
  31.     *
  32.     * DESCRIPTION
  33.     *  
  34.     * <code>XMLFormatter</code> is a <code>Formatter</code> designed to 
  35.     * format log messages using a XML representation. 
  36.     * 
  37.     * 
  38.     * var cfgLogger = NOF.UTIL.LOGGING.getLogger("myModuleName");
  39.     * var cHndl   = new NOF.UTIL.LOGGING.ConsoleHandler(cfgLogger);
  40.     * cHndl.setFormatter( new NOF.UTIL.LOGGING.XMLFormatter() );
  41.     * cfgLogger.addHandler( cHndl );
  42.     * cfgLogger.warning(" {0} is {2} times stronger than {1}! ", "mySourceClass", "mySourceMethod", ["Superman", "Batman", 3] );  
  43.     * // will generate an output like:
  44.     * // <logEntry><source><className>mySourceClass</className><methodName>mySourceMethod</methodName></source>
  45.     * // <time>1062495263501</time><level>WARNING</level>
  46.     * // <message> Superman is 3 times stronger than Batman! </message></logEntry>
  47.     * // ...
  48.     * try {
  49.     *   cHndl.close();
  50.     * } catch (closing_e) {
  51.     *   // ...
  52.     * }
  53.     *
  54.     ****/ 
  55.   
  56.   /** 
  57.   * constuctor
  58.   **/
  59.   function LOGGING_XMLFormatter( ) {
  60.     this.__proto__ = LOGGING_XMLFormatter.prototype;    
  61.     this.SUPER();        
  62.   }
  63.   
  64.   LOGGING_XMLFormatter.inherits(LOGGING.Formatter)
  65.   {
  66.     var member = LOGGING_XMLFormatter.prototype;    
  67.     member.CLASS_NAME        = "LOGGING.XMLFormatter";
  68.     
  69.     /** 
  70.     * string representing the DTD of the XML nodes 
  71.     * generated by this Formatter.
  72.     **/
  73.     member.DTD                = "<!ELEMENT logEntry  (source, time, level, message) >\
  74.       <!ELEMENT source (className?, methodName?) >\
  75.       <!ELEMENT className  (#PCDATA) >\
  76.       <!ELEMENT methodName  (#PCDATA) >\
  77.       <!ELEMENT time  (#PCDATA) >\
  78.       <!ELEMENT level (SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST) >\
  79.       <!ELEMENT message  (#PCDATA) >";
  80.     
  81.     var method = LOGGING_XMLFormatter.prototype;            
  82.     
  83.     /**
  84.     * Format a log record as a XML node.
  85.     * 
  86.     * @param logRecord log message to be formatted
  87.     * @return  string representation of the XML node 
  88.     **/
  89.     method.format = function (/*NOF.UTIL.LOGGING.LogRecord*/ logRecord) {             
  90.       var str = "<logEntry>";
  91.       var sourceStr = "<source>";
  92.       var tmpStr = logRecord.getSourceClassName();            
  93.       if (tmpStr != null) {
  94.         sourceStr += "<className>" + tmpStr + "</className>";
  95.       }
  96.       tmpStr = logRecord.getSourceMethodName();
  97.       if (tmpStr != null) {
  98.         sourceStr += "<methodName>" + tmpStr + "</methodName>";
  99.       }
  100.       sourceStr += "</source>";
  101.       
  102.       str += (sourceStr + "<time>" + logRecord.getMillis() + "</time>" +
  103.         "<level>" + LOGGING.Level.LEVEL_NAMES[logRecord.getLevel()] + "</level>"+
  104.         "<message>" + this.formatMessage(logRecord) + "</message></logEntry>");
  105.       
  106.       return str;
  107.     }    
  108.   }  
  109.   LOGGING.__proto__.XMLFormatter = LOGGING_XMLFormatter;
  110. }